home *** CD-ROM | disk | FTP | other *** search
- /* This program is designed to londitudinally split files.
- It expects two arguments, the first argument specifies
- the maximum length of the target files, and the second
- the name of the source file.
- The target files are named F0 - Fn.
- */
- #include <stdio.h>
- #include <stdlib.h>
- main(argc,argv)
- int argc;
- char **argv;
- {
- int i, c, x;
- char fp[5];
- FILE *outfile, *infile;
- if (argc != 3)
- {
- printf("Argument error");
- exit(0);
- }
- argv++; /* get the maximum target file size */
- i = atoi(*argv);
- argv++; /* get the source filename*/
- if ((infile = fopen(*argv, "rb")) == NULL)
- {
- perror("Can't open input file");
- exit(0);
- }
- fp[0] = 'F';
- fp[2] = 0;
- c = 0;
- for ((fp[1] = '0'); (((c = getc(infile)) != EOF) && (fp[1] <= '9')); fp[1]++)
- {
- x = 2;
- outfile = fopen(fp, "wb");
- putc(c, outfile);
- while ((x <= i) && ((c = getc(infile)) != EOF))
- {
- putc(c,outfile);
- x++;
- }
- fclose(outfile);
- }
- fclose(infile);
- if (fp[1] > '9')
- printf("Warning - more than 9 files required");
- exit(0);
- }